<?php
function getPlayerDisplay($teamPlayer, $round) {
	$submittedTeams = null;
	if ($round != null) {
		$submittedTeams = getTeamsSubmitted($round);
	}
	$color = 'black';
	if ($teamPlayer == null || $teamPlayer->player == null || $teamPlayer->player->playerFirstName == null) {
		return "___";
	}	
	else if ($teamPlayer->player->playerType == 'RUCK') {
		$color = 'purple';
	}
	else if ($teamPlayer->player->playerType == 'KPP_RUCK') {
		$color = 'red';
	}
	else if ($teamPlayer->player->playerType == 'KPP') {
		$color = 'blue';
	}
	else if ($teamPlayer->player->playerType == 'HALF_KPP') {
		$color = 'green';
	}
		
	$result = '<font color=' . $color . '>' . $teamPlayer->player->playerFirstName . ' ' . $teamPlayer->player->playerSurname;
    $result .= ' (' . getAFLTeam($teamPlayer->player->team) . ')</font>';
	
	if ($teamPlayer->isLtiReplacement) {
		$result .= ' <b>**</b>';
	}
	if ($submittedTeams != null) {
		if ($teamPlayer->positionInAFLTeam != null && $teamPlayer->positionInAFLTeam <> 'EMG' && $teamPlayer->positionInAFLTeam <> 'EXB') {
			$result .= "&nbsp;<img src='../../../images/green-square.JPG'>";
		}
		else if ($teamPlayer->positionInAFLTeam != null && $teamPlayer->positionInAFLTeam == 'EXB') {
			$result .= "&nbsp;<img src='../../../images/yellow-square.JPG'>";
		}
		else if ($teamPlayer->positionInAFLTeam != null && $teamPlayer->positionInAFLTeam == 'EMG') {
			$result .= "&nbsp;<img src='../../../images/blue-square.JPG'>";
		}	 
		else if (hasAFLTeamBeenSubmitted($submittedTeams, $teamPlayer->player->team)) {
			$result .= "&nbsp;<img src='../../../images/red-square.JPG'>";
		}
	}
	
	return $result;
}

function getPlayerDisplayForPlayer($player) {
	$color = 'black';
	if ($player == null || $player->playerFirstName == null) {
		return "___";
	}	
	else if ($player->playerType == 'RUCK') {
		$color = 'purple';
	}
	else if ($player->playerType == 'KPP_RUCK') {
		$color = 'red';
	}
	else if ($player->playerType == 'KPP') {
		$color = 'blue';
	}
	else if ($player->playerType == 'HALF_KPP') {
		$color = 'green';
	}
		
	if ($player->playerFirstName == "Penalty") {
		$result = '<font color=Crimson><b>' . $player->playerFirstName . ' ' . $player->playerSurname . '</b></font>';		
	}
	else {
		$result = '<font color=' . $color . '>' . $player->playerFirstName . ' ' . $player->playerSurname . ' (' . getAFLTeam($player->team) . ')</font>';
	}
	
	return $result;
}

function getPlayerDisplayForAPL($player) {
	$color = 'black';
	if ($player == null || $player->playerFirstName == null) {
		return "___";
	}	
	else if ($player->playerType == 'RUCK') {
		$color = 'purple';
	}
	else if ($player->playerType == 'KPP_RUCK') {
		$color = 'red';
	}
	else if ($player->playerType == 'KPP') {
		$color = 'blue';
	}
	else if ($player->playerType == 'HALF_KPP') {
		$color = 'green';
	}
		
	$result = '<font color=' . $color . '>' . $player->playerFirstName . ' ' . $player->playerSurname;
	
	return $result;
}

function getPlayerDisplayForForum($player) {
	$color = 'black';
	if ($player == null || $player->playerFirstName == null) {
		return "___";
	}	
	else if ($player->playerType == 'RUCK') {
		$color = 'purple';
	}
	else if ($player->playerType == 'KPP_RUCK') {
		$color = 'red';
	}
	else if ($player->playerType == 'KPP') {
		$color = 'blue';
	}
	else if ($player->playerType == 'HALF_KPP') {
		$color = 'green';
	}
		
	$result = '[color=' . $color . ']' . $player->playerFirstName . ' ' . $player->playerSurname;
	 $result .= ' (' . getAFLTeam($player->team) . ')[/color]';
	
	return $result;
}



function displayState($state) {
	if ($state == TradeState::Proposed) {
		return "<font color='green'>" . $state . "</font>";
	}
	else if ($state == TradeState::Countered) {
		return "<font color='green'>" . $state . "</font>";
	}	
	else if ($state == TradeState::Confirmed || $state == TradeState::ConfirmedAndInformed) {
		return "<font color='blue'>CONFIRMED</font>";
	}
	else if ($state == TradeState::Rejected) {
		return "<font color='red'>" . $state . "</font>";
	}
	else if ($state == TradeState::Invalid) {
		return "<font color='red'>" . $state . "</font>";
	}
}

function printItem($item, $type) {
	if (is_array($item)) {
		$count = count($item);
		for ($i = 0; $i < $count; $i++) {
			printSingular($item[$i], $type);
		}
	}
	else {
		printSingular($item, $type);
	}
}

function printSingular($item, $type) {
	if ($type == "LEAGUE") {
		echo "type = LEAGUE" . "<br>";
		echo "id - " . checkNull($item->id) . "<br>";
		echo "name - " . checkNull($item->name) . "<br>";
		echo "year - " . checkNull($item->year) . "<br>";
	}
	else if ($type == "TEAM") {
		echo "type = TEAM" . "<br>";
		echo "id - " . checkNull($item->id) . "<br>";
		echo "coachName - " . checkNull($item->coachName) . "<br>";
		echo "teamName - " . checkNull($item->teamName) . "<br>";
		echo "leagueId - " . checkNull($item->leagueId) . "<br>";
		echo "teamId - " . checkNull($item->teamId) . "<br>";
		echo "password - " . checkNull($item->password) . "<br>";
	}
	else if ($type == "PLAYERDRAFT") {
		echo "type = PLAYERDRAFT" . "<br>";
		echo "round - " . checkNull($item->round) . "<br>";
		echo "pickNumber - " . checkNull($item->pickNumber) . "<br>";
		echo "coachNName - " . checkNull($item->coachNName) . "<br>";
		echo "playerId - " . checkNull($item->playerId) . "<br>";
		echo "player - " . printSingular($item->player, "PLAYER") . "<br>";
	}
	else if ($type == "TEAMPLAYER") {
		echo "type = TEAMPLAYER" . "<br>";
		echo "pickNumber - " . checkNull($item->pickNumber) . "<br>";
		echo "coachNName - " . checkNull($item->coachNName) . "<br>";
		echo "playerId - " . checkNull($item->playerId) . "<br>";
		echo "player - " . printSingular($item->player, "PLAYER") . "<br>";
		echo "playerPosition - " . checkNull($item->playerPosition) . "<br>";
	}
	else if ($type == "PLAYER") {
		echo "type = PLAYER" . "<br>";
		echo "id - " . checkNull($item->id) . "<br>";
		echo "playerFirstName - " . checkNull($item->playerFirstName) . "<br>";
		echo "playerSurname - " . checkNull($item->playerSurname) . "<br>";
		echo "team - " . checkNull($item->team) . "<br>";
		echo "playerType - " . checkNull($item->playerType) . "<br>";
	}
	else if ($type == "PLAYERFORROUND") {
		echo "type = PLAYERFORROUND" . "<br>";
		echo "teamId - " . checkNull($item->teamId) . "<br>";
		echo "round - " . checkNull($item->round) . "<br>";
		echo "playerId - " . checkNull($item->playerId) . "<br>";
		echo "replacementPlayerId - " . checkNull($item->replacementPlayerId) . "<br>";
	}
	else if ($type == "FIXTUREROUND") {
		echo "type = FIXTUREROUND" . "<br>";
		echo "round - " . checkNull($item->round) . "<br>";
		echo "fixtures - " . printItem($item->fixtures, "FIXTURE") . "<br>";
	}
	else if ($type == "FIXTURE") {
		echo "type = FIXTURE" . "<br>";
		echo "homeTeamId - " . checkNull($item->homeTeamId) . "<br>";
		echo "awayTeamId - " . checkNull($item->awayTeamId) . "<br>";
		echo "gameNumber - " . checkNull($item->gameNumber) . "<br>";
		echo "round - " . checkNull($item->round) . "<br>";
		echo "leagueId - " . checkNull($item->leagueId) . "<br>";
	}
	else if ($type == "TRADEITEM") {
		echo "type = TRADEITEM" . "<br>";
		echo "itemType - " . checkNull($item->itemType) . "<br>";
		echo "player - " . printSingular($item->player) . "<br>";
		echo "pickNumber - " . checkNull($item->pickNumber) . "<br>";
	}
	else if ($type == "TRADE") {
		echo "type = TRADE" . "<br>";
		echo "id - " . checkNull($item->id) . "<br>";
		echo "partyOneId - " . checkNull($item->partyOneId) . "<br>";
		echo "partyTwoId - " . checkNull($item->partyTwoId) . "<br>";
		echo "partyOne - " . checkNull($item->partyOne) . "<br>";
		echo "partyTwo - " . checkNull($item->partyTwo) . "<br>";
		echo "state - " . checkNull($item->state) . "<br>";
		echo "partyOneReceives - " . printItem($item->partyOneReceives, "TRADEITEM") . "<br>";
		echo "partyTeoReceives - " . printItem($item->partyTwoReceives, "TRADEITEM") . "<br>";
	}
	else if ($type == "SELECTEDTEAM") {
		echo "type = SELECTEDTEAM" . "<br>";
		echo "teamName - " . checkNull($item->teamName) . "<br>";
		echo "youPicks - " . printItem($item->yourPicks, "TeamPlayer") . "<br>";
	}
	else if ($type == "TEAMRESULT") {
		echo "type = TEAMRESULT" . "<br>";
		echo "team - " . checkNull($item->team) . "<br>";
		echo "gamesWon - " . checkNull($item->gamesWon) . "<br>";
		echo "gamesDrawn - " . checkNull($item->gamesDrawn) . "<br>";
		echo "forValue - " . checkNull($item->forValue) . "<br>";
		echo "againstValue - " . checkNull($item->againstValue) . "<br>";
		echo "numberPlayersSelectedForCurrentRound - " . checkNull($item->numberPlayersSelectedForCurrentRound) . "<br>";
		echo "numberPlayersSelected - " . checkNull($item->numberPlayersSelected) . "<br>";
		echo "numberPlayersnumberGames - " . checkNull($item->numberGames) . "<br>";
		echo "lowestScore - " . checkNull($item->lowestScore) . "<br>";		
		echo "highestScore - " . checkNull($item->highestScore) . "<br>";
		echo "isWinningStreak - " . checkNull($item->isWinningStreak) . "<br>";
		echo "streak - " . checkNull($item->streak) . "<br>";
	}	
}

function checkNull($item) {
	if ($item == null) return "null";
	else return $item;
}

function getArchiveDisplay($leagueId, $year, $round) {
	$weekFourGameResults = getGameResults($round + 4, $leagueId, $year, true);
	$weekThreeGameResults = getGameResults($round + 3, $leagueId, $year, true);
	$weekTwoGameResults = getGameResults($round + 2, $leagueId, $year, true);
	$weekOneGameResults = getGameResults($round + 1, $leagueId, $year, true);			
	$coachResults = getCoachResults($leagueId, $round, $year, true);
	$result = "<table align='center' width='65%'><tr><td><table>";
	$result .= "<tr>";
	$result .= "<td><a href='javascript: getArchive(1, 20, 2011, 1);'>SAD 2011</a></td>";
	$result .= "</tr>";
	$result .= "<tr>";
	$result .= "<td><a href='javascript: getArchive(2, 20, 2011, 2);'>AAD 2011</a></td>";
	$result .= "</tr>";
	$result .= "<tr>";
	$result .= "<td><a href='javascript: getArchive(5, 17, 2010, 3);'>Div 1 2010</a></td>";
	$result .= "</tr>";
	$result .= "<tr>";
	$result .= "<td><a href='javascript: getArchive(6, 17, 2010, 4);'>Div 2 2010</a></td>";
	$result .= "</tr>";
	$result .= "<tr>";
	$result .= "<td><a href='javascript: getArchive(7, 18, 2009, 5);'>Div 2 2010</a></td>";
	$result .= "</tr>";	
	$result .= "</table></td><td><td><table align='center' width='75%' cellpadding='5'>";
	$result .= "<tr><td colspan=9 width=100% align='center'><b>Grand Final</b></td></tr>";
	$result .= "<tr><td colspan=9 width=100%>" . displayGameResults($weekFourGameResults, 1) . "<br><br></td></tr>";
	$result .= "<tr><td colspan=9 width=100% align='center'><b>Pre-lim Finals</b></td></tr>";
	$result .= "<tr><td colspan=9 width=100%>" . displayGameResults($weekThreeGameResults, 2) . "<br><br></td></tr>";
	$result .= "<tr><td colspan=9 width=100% align='center'><b>Semi Finals</b></td></tr>";
	$result .= "<tr><td colspan=9 width=100%>" . displayGameResults($weekTwoGameResults, 2) . "<br><br></td></tr>";
	$result .= "<tr><td colspan=9 width=100% align='center'><b>Elimination/Qualifying Final</b></td></tr>";
	$result .= "<tr><td colspan=9 width=100%>" . displayGameResults($weekOneGameResults, 4) . "<br><br></td></tr>";
	$result .= "<tr><td colspan=9 width=100% align='center'><b>Ladder after H&A</b></td></tr>";
	$result .= "<tr>";
	$result .= "<td width='20%'><b>Team name</b></td>";
	$result .= "<td width='10%'><b>Won</b></td>";
	$result .= "<!-- td width='10%'><b>Drawn</b></td -->";
	$result .= "<td width='10%'><b>For</b></td>";
	$result .= "<td width='10%'><b>Against</b></td>";
	$result .= "<td width='10%'><b>%</b></td>";
	$result .= "<td width='10%'><b>Highest</b></td>";
	$result .= "<td width='10%'><b>Lowest</b></td>";
	$result .= "<td width='10%'><b>Average</b></td>";
	$result .= "<td width='10%'><b>Streak</b></td>";
	$result .= "</tr>";
	$count = count($coachResults);
	for ($i = 0; $i < $count; $i++) {
		$result .= "<tr>";
		$result .= "<td width='20%'>" . $coachResults[$i]->team->teamName . "</td>";
		$result .= "<td width='10%'>" . $coachResults[$i]->gamesWon . "</td>";
		$result .= "<!--  td width='10%'><s:property value='gamesDrawn' /></td -->";
		$result .= "<td width='10%'>" . $coachResults[$i]->forValue . "</td>";
		$result .= "<td width='10%'>" . $coachResults[$i]->againstValue . "</td>";
		$result .= "<td width='10%'>" . $coachResults[$i]->getPercentage() . "</td>";
		$result .= "<td width='10%'>" . $coachResults[$i]->highestScore . "</td>";
		$result .= "<td width='10%'>" . $coachResults[$i]->lowestScore . "</td>";
		$result .= "<td width='10%'>" . $coachResults[$i]->getAverageScore() . "</td>";
		$result .= "<td width='10%'>" . $coachResults[$i]->getStreakVal() . "</td>";
		$result .= "</tr>";
		if ($i == 7) {
			$result .= "<tr>";
			$result .= "<td colspan=9><hr></td>";
			$result .= "</tr>";
		}
	}
	$result .= "</table></td></tr></table>";
	
	return $result;
}

function getLeagueId() {
	return $_SESSION['leagueId'];
}

function getLoggedInTeam() {
	session_start();
	$team = null;
	$loggedInUser = "";
	if (isset($_GET['letMeInNow']) && isset($_GET['leagueId']) && $_GET['leagueId'] != "") {
	   $loggedInUser = $_GET['letMeInNow'];
	   $_SESSION['leagueId'] = $_GET['leagueId'];
	   
	   $team = getTeam($loggedInUser, $_SESSION['leagueId']);
	   $_SESSION['loggedInTeam'] = $team;
	}
	else if (isset($_POST['username']) && isset($_POST['leagueId']) && $_POST['leagueId'] != ""){
		$loggedInUser = $_POST['username'];
		$_SESSION['leagueId'] = $_POST['leagueId'];
		
		$team = getTeam($loggedInUser, $_SESSION['leagueId']);
		$_SESSION['loggedInTeam'] = $team;
	}
//	else if (!isset($_POST['username']) && isset($_SESSION['boardMember'])) {
//		echo "IN HERE111111!!!!!!!!";
//		$loggedInUser = $_SESSION['boardMember'];
//		$team = getTeam($loggedInUser, $_SESSION['leagueId']);
//	}	
	else if (isset($_SESSION['loggedInTeam']) && $_SESSION['loggedInTeam'] != null) {
		$team = $_SESSION['loggedInTeam'];
	}
	
	if (!isset($_SESSION) || !isset($_SESSION['leagueId'])) {
		$team = null;
	}

	return $team;
}

function getSelectString($position, $players, $myTeam, $status, $partialLockoutTeams) {
	$ltiReturns = getReturnedLtisForCoach($myTeam->id);
	$count = count($players);
	$selectString =  "<select id=\"$position\" name=\"$position\"><option value=\"-1\">Select a Player</option>";
	for ($i = 0; $i < $count; $i++) {
		$selected = false;
		if (($position == 'R' && ($players[$i]->player->playerType == 'RUCK' || $players[$i]->player->playerType == 'KPP_RUCK')) || $position != 'R') {
			if (!isReplacementOfReturnedLti($ltiReturns, $players[$i]->player)) {
				$optionString = "<option value=\"" . $players[$i]->player->id . "\"";
				if ($myTeam->getPlayer($position) != null && $myTeam->getPlayer($position)->player->id == $players[$i]->player->id) {
					$optionString .= " selected";
					$selected = true;
				}
				$optionString .= ">" . $players[$i]->player->getDescription();
				if ($players[$i]->playerPosition != null && $players[$i]->playerPosition != "RES") {
	            	if (substr($players[$i]->playerPosition, 0, 1) == "E") {
	 				   $optionString .= "[EMG]";
	                }
	                else {
	                	$optionString .= "[SELECTED]";
	                }
				}
				$optionString .= "</option>";
				if ($selected || ($status == null || $status == RoundStatusType::Open || ($status == RoundStatusType::Partial_Lockout && !isTeamPartiallyLockedOut($partialLockoutTeams, $players[$i]->player->team)))) {
					$selectString .= $optionString;
				}
			}
		} 
	}
	$selectString .= "</select>";
	
	return $selectString;
}

function getConfig() {
	$reqPathPrefix = "../../..";
	if (PHP_OS == "Linux") {
		$reqPathPrefix = "/var/www/masoCoach";
	}
	$configFile = parse_ini_file($reqPathPrefix . "/config/config.ini", true);
	$config = new Config();
	if ($configFile["dev"]["use"]) {
		$config->server = $configFile["dev"]["server"];  
		$config->username = $configFile["dev"]["username"];
		$config->password = $configFile["dev"]["password"];
		$config->schema = $configFile["dev"]["schema"];		
		$config->hours = $configFile["dev"]["hours"];
	}
	else {
		$config->server = $configFile["prod"]["server"];  
		$config->username = $configFile["prod"]["username"];
		$config->password = $configFile["prod"]["password"];
		$config->schema = $configFile["prod"]["schema"];
		$config->hours = $configFile["prod"]["hours"];		
	}
	
	return $config;
}

function getPosition($positionLine, $index) {
	if ($positionLine == "B" && $index == 0) {
		return "LBP";
	}
	else if ($positionLine == "B" && $index == 1) {
		return "FB";
	}
	else if ($positionLine == "B" && $index == 2) {
		return "RBP";
	}
	else if ($positionLine == "HB" && $index == 0) {
		return "LHBF";
	}
	else if ($positionLine == "HB" && $index == 1) {
		return "CHB";
	}
	else if ($positionLine == "HB" && $index == 2) {
		return "RHBF";
	}
	else if ($positionLine == "C" && $index == 0) {
		return "LW";
	}
	else if ($positionLine == "C" && $index == 1) {
		return "C";
	}
	else if ($positionLine == "C" && $index == 2) {
		return "RW";
	}
    else if ($positionLine == "HF" && $index == 0) {
		return "LHFF";
	}
	else if ($positionLine == "HF" && $index == 1) {
		return "CHF";
	}
	else if ($positionLine == "HF" && $index == 2) {
		return "RHFF";
	}
	else if ($positionLine == "F" && $index == 0) {
		return "LFP";
	}
	else if ($positionLine == "F" && $index == 1) {
		return "FF";
	}
	else if ($positionLine == "F" && $index == 2) {
		return "RFP";
	}
	else if (($positionLine == "Foll" || $positionLine == "Followers") && $index == 0) {
		return "R";
	}
	else if (($positionLine == "Foll" || $positionLine == "Followers") && $index == 1) {
		return "F1";
	}
	else if (($positionLine == "Foll" || $positionLine == "Followers") && $index == 2) {
		return "F2";
	}	
	else if ($positionLine == "I/C" || $positionLine == "Interchange" || $positionLine == "Sub") {
		return "IC";
	}
	else if ($positionLine == "Emg") {
		return "EMG";
	}
}

function getPlayerValidityKey() {
	$result = "<table><tr><td><img src='../../../images/green-square.JPG'></td><td>Selected(Valid)</td><td><img src='../../../images/yellow-square.JPG'></td><td>Extended Bench(Valid)</td></tr>";
	$result .= "<tr><td><img src='../../../images/blue-square.JPG'></td><td>Emergency(Invalid)</td><td><img src='../../../images/red-square.JPG'></td><td>Not Selected(Invalid)</td></tr></table>";	
	
	return $result;
}

function getPlayerReplacementNames() {
	$players = array();

    $players[] = new PlayerReplacementName("Jamie", "Elliott", "Collingwood", "James", "Elliott");
    $players[] = new PlayerReplacementName("Tom", "Sheridan", "Fremantle", "Thomas", "Sheridan");
    $players[] = new PlayerReplacementName("Josh", "Walker", "Collingwood", "Joshua", "Walker");
    $players[] = new PlayerReplacementName("Sam", "Dunell", "St Kilda", "Sam", "Dunnell");
    $players[] = new PlayerReplacementName("Stephen", "Clifton", "Greater Western Sydney", "Steve", "Clifton");
    $players[] = new PlayerReplacementName("Setanta", "Ó hAilpín", "Greater Western Sydney", "Setanta", "O'hAilpin");	
	$players[] = new PlayerReplacementName("Jacob", "Gillbee", "Gold Coast", "Jacob", "Gilbee"); 
    $players[] = new PlayerReplacementName("Cory", "Dell'Olio", "Greater Western Sydney", "Corey", "Dell'Olio");
    $players[] = new PlayerReplacementName("Cameron", "Pederson", "North Melbourne", "Cameron", "Pedersen");
    $players[] = new PlayerReplacementName("Thomas", "Swift", "West Coast", "Tom", "Swift");
    $players[] = new PlayerReplacementName("Mitchell J.", "Brown", "West Coast", "Mitchell", "Brown");
	$players[] = new PlayerReplacementName("Sam J.", "Reid", "Greater Western Sydney", "Sam", "Reid");
	$players[] = new PlayerReplacementName("Mitch", "Brown", "Geelong", "Mitchell", "Brown");
	$players[] = new PlayerReplacementName("WIlliam", "Hoskin-Elliot", "Greater Western Sydney", "William", "Hoskin-Elliott");
	$players[] = new PlayerReplacementName("Brad", "McKenzie", "North Melbourne", "Bradley", "McKenzie");
	$players[] = new PlayerReplacementName("Mitchell", "Wallis", "Western Bulldogs", "Mitch", "Wallis");
	$players[] = new PlayerReplacementName("William", "Minson", "Western Bulldogs", "Will", "Minson");
	$players[] = new PlayerReplacementName("Zachary", "Clarke", "Fremantle", "Zach", "Clarke");
	$players[] = new PlayerReplacementName("Jack", "Anthony", "Fremantle", "John", "Anthony");
	$players[] = new PlayerReplacementName("Bradley", "Ebert", "Port Adelaide", "Brad", "Ebert");
	$players[] = new PlayerReplacementName("Tom T.", "Lynch", "Adelaide", "Tom", "Lynch");
	$players[] = new PlayerReplacementName("Tom J.", "Lynch", "Gold Coast", "Tom", "Lynch");
	$players[] = new PlayerReplacementName("Heritier", "O'Brien", "Collingwood", "Harry", "O'Brien");	 
	$players[] = new PlayerReplacementName("Marty", "Clarke", "Collingwood", "Marty", "Clark");	 
	$players[] = new PlayerReplacementName("Martin", "Clarke", "Collingwood", "Marty", "Clark");
	$players[] = new PlayerReplacementName("Matt", "Dea", "Richmond", "Matthew", "Dea");
	$players[] = new PlayerReplacementName("Bradley", "Helbig", "Richmond", "Brad", "Helbig");
	$players[] = new PlayerReplacementName("Edward", "Curnow", "Carlton", "Ed", "Curnow");
	$players[] = new PlayerReplacementName("Lachie", "Henderson", "Carlton", "Lachlan", "Henderson");
	$players[] = new PlayerReplacementName("Chris", "Yarran", "Carlton", "Christopher", "Yarran");
	$players[] = new PlayerReplacementName("Sam B.", "Reid", "Sydney", "Sam", "Reid");
	$players[] = new PlayerReplacementName("Jonathan", "Giles", "Greater Western Sydney", "Jonathon", "Giles");
	$players[] = new PlayerReplacementName("Curtly", "Hampton", "Greater Western Sydney", "Curtley", "Hampton");
	$players[] = new PlayerReplacementName("Will", "Hoskin-Elliot", "Greater Western Sydney", "William", "Hoskin-Elliott");
	$players[] = new PlayerReplacementName("Will", "Hoskin-Elliott", "Greater Western Sydney", "William", "Hoskin-Elliott");
	$players[] = new PlayerReplacementName("Lachie", "Henderson", "Carlton", "Lachlan", "Henderson");
	$players[] = new PlayerReplacementName("Chris", "Yarran", "Carlton", "Christopher", "Yarran");
	$players[] = new PlayerReplacementName("Scott", "D. Thompson", "North Melbourne", "Scott", "Thompson");
	$players[] = new PlayerReplacementName("Sam", "Wright", "North Melbourne", "Samuel", "Wright");
	$players[] = new PlayerReplacementName("Josh", "P. Kennedy", "Sydney", "Josh", "Kennedy");
	$players[] = new PlayerReplacementName("L.", "Roberts-Thomson", "Sydney", "Lewis", "Roberts-Thomson");
	$players[] = new PlayerReplacementName("Matt", "Maguire", "Brisbane", "Matthew", "Maguire");
	$players[] = new PlayerReplacementName("S.", "Prestigiacomo", "Collingwood", "Simon", "Prestigiacomo");
	$players[] = new PlayerReplacementName("Ben", "Stratton", "Hawthorn", "Benjamin", "Stratton");
	$players[] = new PlayerReplacementName("Jefferey", "Garlett", "Carlton", "Jeff", "Garlett");
	$players[] = new PlayerReplacementName("Lachie", "Hansen", "North Melbourne", "Lachlan", "Hansen");
	$players[] = new PlayerReplacementName("Scott D.", "Thompson", "North Melbourne", "Scott", "Thompson");
	$players[] = new PlayerReplacementName("Josh P.", "Kennedy", "Sydney", "Josh", "Kennedy");
	$players[] = new PlayerReplacementName("Josh J.", "Kennedy", "West Coast", "Joshua", "Kennedy");
	$players[] = new PlayerReplacementName("Josh", "Kennedy", "West Coast", "Joshua", "Kennedy");
	$players[] = new PlayerReplacementName("Nick", "Naitanui", "West Coast", "Nicholas", "Naitanui");
	$players[] = new PlayerReplacementName("Nic", "Naitanui", "West Coast", "Nicholas", "Naitanui");
	$players[] = new PlayerReplacementName("Matt", "Priddis", "West Coast", "Matthew", "Priddis");
	$players[] = new PlayerReplacementName("Matt", "Rosa", "West Coast", "Matthew", "Rosa");
	$players[] = new PlayerReplacementName("Matt", "Spangher", "West Coast", "Matthew", "Spangher");
	$players[] = new PlayerReplacementName("Ricky", "Dyson", "Essendon", "Rick", "Dyson");
	$players[] = new PlayerReplacementName("Matt", "White", "Richmond", "Matthew", "White");
	$players[] = new PlayerReplacementName("Mitch", "Duncan", "Geelong", "Mitchell", "Duncan");
	$players[] = new PlayerReplacementName("Robbie", "Gray", "Port Adelaide", "Robert", "Gray");
	$players[] = new PlayerReplacementName("Chris", "Mayne", "Fremantle", "Christopher", "Mayne");
	$players[] = new PlayerReplacementName("Mitch", "Clark", "Brisbane", "Mitchell", "Clark");
	$players[] = new PlayerReplacementName("Nathan J.", "Brown", "Collingwood", "Nathan", "Brown");
	$players[] = new PlayerReplacementName("Ben", "McKinley", "West Coast", "Benjamin", "McKinley");
	$players[] = new PlayerReplacementName("Danny", "Hughes", "Melbourne", "Daniel", "Hughes");
	$players[] = new PlayerReplacementName("Matt", "Suckling", "Hawthorn", "Matthew", "Suckling");
	$players[] = new PlayerReplacementName("Chris", "Johnson", "Carlton", "Christopher", "Johnson");
	$players[] = new PlayerReplacementName("Nick", "Suban", "Fremantle", "Nicholas", "Suban");
	$players[] = new PlayerReplacementName("Zac", "Clarke", "Fremantle", "Zach", "Clarke");
	$players[] = new PlayerReplacementName("Robbie", "Tarrant", "North Melbourne", "Robert", "Tarrant");
	$players[] = new PlayerReplacementName("Andrew L.", "Browne", "Richmond", "Andrew", "Browne");
	$players[] = new PlayerReplacementName("Benjamin", "Speight", "North Melbourne", "Ben", "Speight");
	$players[] = new PlayerReplacementName("Brad", "Fisher", "Carlton", "Bradley", "Fisher");
	$players[] = new PlayerReplacementName("Robbie", "Hicks", "Richmond", "Robert", "Hicks");
	$players[] = new PlayerReplacementName("Jamie", "O'Rielly", "Richmond", "James", "O'Rielly");
	$players[] = new PlayerReplacementName("Brad", "Moran", "Adelaide", "Bradley", "Moran");
	$players[] = new PlayerReplacementName("Dan", "Nicholson", "Melbourne", "Daniel", "Nicholson");
	$players[] = new PlayerReplacementName("Thomas", "Ledger", "St Kilda", "Tom", "Ledger");
	$players[] = new PlayerReplacementName("Nick", "Winmar", "St Kilda", "Nicholas", "Winmar");
	$players[] = new PlayerReplacementName("Joshua", "Green", "Brisbane", "Josh", "Green");
	$players[] = new PlayerReplacementName("Thomas", "Nicholls", "Gold Coast", "Tom", "Nicholls");
	$players[] = new PlayerReplacementName("Sebastian", "Tape", "Gold Coast", "Seb", "Tape");
	$players[] = new PlayerReplacementName("Matthew", "Shaw", "Gold Coast", "Matt", "Shaw");
	$players[] = new PlayerReplacementName("Ben", "McKinley", "North Melbourne", "Benjamin", "McKinley");
	$players[] = new PlayerReplacementName("Edward", "Curnow", "Carlton", "Ed", "Curnow");
	$players[] = new PlayerReplacementName("Bradley", "Helbig", "Richmond", "Brad", "Helbig");
	$players[] = new PlayerReplacementName("Heritier", "O''Brien", "Collingwood", "Harry", "O''Brien");
	$players[] = new PlayerReplacementName("Nick", "Duigan", "Carlton", "Nicholas", "Duigan");
	$players[] = new PlayerReplacementName("Jeffrey", "Garlett", "Carlton", "Jeff", "Garlett");
	$players[] = new PlayerReplacementName("Matthew", "de Boer", "Fremantle", "Matthew", "DeBoer");
	$players[] = new PlayerReplacementName("Daniel", "Stanley", "Gold Coast", "Danny", "Stanley");
	$players[] = new PlayerReplacementName("Mitch", "Brown", "West Coast", "Mitchell", "Brown");
	$players[] = new PlayerReplacementName("Bradley", "Ebert", "West Coast", "Brad", "Ebert");
	$players[] = new PlayerReplacementName("Tom", "L. Williams", "Western Bulldogs", "Tom", "Williams");
	$players[] = new PlayerReplacementName("Thomas", "Liberatore", "Western Bulldogs", "Tom", "Liberatore");
	$players[] = new PlayerReplacementName("Nicholas", "Smith", "Sydney", "Nick", "Smith");
	$players[] = new PlayerReplacementName("Sebastian", "Tape", "Gold Coast", "Seb", "Tape");
	$players[] = new PlayerReplacementName("Zachary", "Smith", "Gold Coast", "Zac", "Smith");
	$players[] = new PlayerReplacementName("Josh", "Toy", "Gold Coast", "Joshua", "Toy");
	$players[] = new PlayerReplacementName("Keiran", "Harper", "North Melbourne", "Kieran", "Harper");
	$players[] = new PlayerReplacementName("Brad", "Sheppard", "West Coast", "Bradley", "Sheppard");
	$players[] = new PlayerReplacementName("Aidan", "Riley", "Adelaide", "Aiden", "Riley");
	$players[] = new PlayerReplacementName("Alexander", "Fasolo", "Collingwood", "Alex", "Fasolo");
	$players[] = new PlayerReplacementName("Ben", "Bucovaz", "Fremantle", "Benjamin", "Bucovaz");
	$players[] = new PlayerReplacementName("Niall", "McKeever", "Brisbane", "Nial", "McKeever");
	$players[] = new PlayerReplacementName("Matthew", "Spangher", "Sydney", "Matt", "Spangher");
	$players[] = new PlayerReplacementName("Ben", "Griffiths", "Richmond", "Benjamin", "Griffiths");
	
	return $players;
}

function getPlayerInfoIcon($playerInfo) {
	return "<a href=\"#\" onmouseover=\"this.style.color = '#D17E62'; domTT_activate(this, event, 'content', '$playerInfo', 'trail', true, 'fade', 'both', 'fadeMax', 87, 'styleClass', 'niceTitle');\" onmouseout=\"this.style.color = ''; domTT_mouseout(this, event);\"><img src=\"../../../images/info.jpg\" width=\"15px\" height=\"15px\"></a>";
}

function isDefence($position) {
	return $position == "LBP" || $position == "FB" || $position == "RBP" || $position == "LHBF" || $position == "CHB" || $position == "RHBF";
}

function isReturnedLti($returnedLtis, $player) {
	foreach ($returnedLtis as $returnedLti) {
		if ($player->getDescription() == $returnedLti->playerOne->getDescription()) {
			return $returnedLti;
		}
	}
	
	return null;
}

function getLtiSpudEntry($ltis, $player) {
	foreach ($ltis as $lti) {
		if ($player->getDescription() == $lti->playerOne->getDescription()) {
			return $lti;
		}
	}
	
	return null;
}

function isReplacementOfReturnedLti($returnedLtis, $player) {
	foreach ($returnedLtis as $returnedLti) {
		if ($player->getDescription() == $returnedLti->playerTwo->getDescription()) {
			return $returnedLti;
		}
	}
	
	return null;
}

?>